#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Created on 2022-04-06 14:11:06
@author: DengLibin 榆霖
@description: 
'''
from msilib.schema import Error
import os
import zipfile

def run(dir):
    if not os.path.exists('unzips'):
        os.makedirs('unzips')
    # 获取path下所有文件的文件名,此时返回的是列表
    rel_path = os.listdir(dir)
    for path in  rel_path:
        if path.endswith('.zip'):
            p = '%s/%s' % (dir,path)
            try:
                f = zipfile.ZipFile(p,'r') # 压缩文件位置
                for file in f.namelist():
                    if file.endswith('.txt'):
                        f.extract(file,"./unzips/")               # 解压位置
                    f.close()
            except:
                continue


if __name__ == '__main__':
    run("files")